//
//  PayOrderTool.m
//  FactorySale
//
//  Created by 主事丫环HU on 2020/8/5.
//  Copyright © 2020 主事丫环. All rights reserved.
//

#import "PayOrderTool.h"
#import <AlipaySDK/AlipaySDK.h>
#import "WXApi.h"

@implementation PayOrderTool

#pragma mark - aliPay
+ (void)aliPay:(NSString *)orderstr {

    //应用注册scheme,在AliSDKDemo-Info.plist定义URL types
    NSString *appScheme = @"zhushiyahuan";

    // NOTE: 将签名成功字符串格式化为订单字符串,请严格按照该格式
    //NSString *orderString = [NSString stringWithFormat:@"%@&sign=%@",orderInfoEncoded, signedString];
    // NOTE: 调用支付结果开始支付
    [[AlipaySDK defaultService] payOrder:orderstr fromScheme:appScheme callback:^(NSDictionary *resultDic) {
        NSLog(@"resultDic----%@",resultDic);

        if ([[resultDic objectForKey:@"resultStatus"]isEqualToString:@"9000"]) {
            //支付成功了
            [Center postNotificationName:@"PaySuccess" object:nil];
        }else {
            [Center postNotificationName:@"PayFail" object:nil];
        }
    }];
}

+ (void)wxPay:(NSDictionary *)dict {
    PayReq* req             = [[PayReq alloc] init];
    req.partnerId           = [dict objectForKey:@"partnerid"];
    req.prepayId            = [dict objectForKey:@"prepayid"];
    req.nonceStr            = [dict objectForKey:@"noncestr"];
    
    UInt32 timeStamp        = [[dict objectForKey:@"timestamp"] intValue];
    req.timeStamp           = timeStamp;
    req.package             = [dict objectForKey:@"package"];
    req.sign                = [dict objectForKey:@"sign"];
        NSLog(@"appid=%@\npartid=%@\nprepayid=%@\nnoncestr=%@\ntimestamp=%ld\npackage=%@\nsign=%@",[dict objectForKey:@"appid"],req.partnerId,req.prepayId,req.nonceStr,(long)req.timeStamp,req.package,req.sign );
    [WXApi sendReq:req];
}

@end
